package ru.rchervot.sanasar.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class AbstractResultsFooterView extends Composite
implements ResultsFooterPresenter.Display {
private final HorizontalPanel basePanel = new HorizontalPanel();
	
	private final HorizontalPanel rightPanel = new HorizontalPanel();
	
	Button first = new Button();
	Button prev = new Button();
	Button next = new Button();
	Button last = new Button();

//	protected ActionMessagesWidget actionMessages = new ActionMessagesWidget(); 
	
	private ResultsFooterPresenter presenter;
	
	public AbstractResultsFooterView() {
		super();
		
		first.setText("«");
		prev.setText("‹");
		next.setText("›");
		last.setText("»");
		
		first.setEnabled(false);
		prev.setEnabled(false);
		next.setEnabled(false);
		last.setEnabled(false);
		
		rightPanel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
		rightPanel.add(new Label("Page:"));
		rightPanel.add(first);
		rightPanel.add(prev);
		rightPanel.add(next);
		rightPanel.add(last);
		rightPanel.setStylePrimaryName("AbstractResultsFooterView_Right");

		
//		first.addClickHandler(navFirst);
//		prev.addClickHandler(navPrev);
//		next.addClickHandler(navNext);
//		last.addClickHandler(navLast);
		

		basePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); // should be before setCellHorizontalAlignment

		basePanel.add(rightPanel);
		basePanel.setCellHorizontalAlignment(rightPanel, HasHorizontalAlignment.ALIGN_RIGHT);
		
		basePanel.setHeight(Constants.kResultsFooterHeight + "px");
		basePanel.setWidth("100%");
		basePanel.setStylePrimaryName("AbstractResultsFooterView");
		
		this.initWidget(basePanel);
	}
	
	@Override
	public void setPresenter(ResultsFooterPresenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public void setEnabledButtonFirst(boolean enabled) {
		first.setEnabled(enabled);
	}

	@Override
	public void setEnabledButtonLast(boolean enabled) {
		last.setEnabled(enabled);
	}

	@Override
	public void setEnabledButtonNext(boolean enabled) {
		next.setEnabled(enabled);
	}

	@Override
	public void setEnabledButtonPrev(boolean enabled) {
		prev.setEnabled(enabled);
	}
	
	@Override
	public HasClickHandlers getPageFirstButton() {
		return first;
	}

	@Override
	public HasClickHandlers getPageLastButton() {
		return last;
	}

	@Override
	public HasClickHandlers getPageNextButton() {
		return next;
	}

	@Override
	public HasClickHandlers getPagePrevButton() {
		return prev;
	}

	
}
